Loading the Survival package
require(survival)
Loading the dataset considered with EXCEL.
dataset = read.table('donnees.txt')
names(dataset)=c('Time','delta')
head(dataset)
## Time delta
## 1 115 0
## 2 310 1
## 3 311 0
## 4 332 0
## 5 377 1
## 6 410 1
Nonparametric estimation can be obtained to the function.
kmfit<-survfit(Surv(Time,delta)~1,data=dataset,conf.type="plain",type='kaplan-meier')
print(kmfit)
## Call: survfit(formula = Surv(Time, delta) ~ 1, data = dataset, conf.type = "plain",
## type = "kaplan-meier")
##
## n events median 0.95LCL 0.95UCL
## 50 17 1443 922 1855
summary(kmfit)
## Call: survfit(formula = Surv(Time, delta) ~ 1, data = dataset, conf.type = "plain",
## type = "kaplan-meier")
##
## time n.risk n.event survival std.err lower 95% CI upper 95% CI
## 310 49 1 0.980 0.0202 0.9400 1.000
## 377 46 1 0.958 0.0289 0.9017 1.000
## 410 45 1 0.937 0.0352 0.8680 1.000
## 471 41 1 0.914 0.0411 0.8336 0.995
## 548 38 1 0.890 0.0465 0.7989 0.981
## 586 35 1 0.865 0.0517 0.7633 0.966
## 605 32 1 0.838 0.0567 0.7265 0.949
## 635 30 1 0.810 0.0613 0.6896 0.930
## 710 22 1 0.773 0.0687 0.6383 0.908
## 844 18 1 0.730 0.0771 0.5788 0.881
## 880 15 1 0.681 0.0860 0.5128 0.850
## 922 14 1 0.633 0.0926 0.4512 0.814
## 925 13 1 0.584 0.0974 0.3930 0.775
## 1030 8 1 0.511 0.1092 0.2969 0.725
## 1443 5 1 0.409 0.1265 0.1609 0.657
## 1449 4 1 0.307 0.1297 0.0523 0.561
## 1855 2 1 0.153 0.1263 0.0000 0.401
plot(kmfit)
For Nelson-Aalen estimation, we have to use the Fleming-Harrington estimate of the Reliability function and use the link between Reliability and Cumulative Hazard rate in case of continuous r.v. \[ R(t)=\exp(-\Lambda(t)) \]
NAfit<-survfit(Surv(Time,delta)~1,data=dataset,conf.type="plain",type='fh')
print(NAfit)
## Call: survfit(formula = Surv(Time, delta) ~ 1, data = dataset, conf.type = "plain",
## type = "fh")
##
## n events median 0.95LCL 0.95UCL
## 50 17 1443 922 NA
summary(NAfit)
## Call: survfit(formula = Surv(Time, delta) ~ 1, data = dataset, conf.type = "plain",
## type = "fh")
##
## time n.risk n.event survival std.err lower 95% CI upper 95% CI
## 310 49 1 0.980 0.0202 0.9402 1.000
## 377 46 1 0.959 0.0289 0.9021 1.000
## 410 45 1 0.938 0.0353 0.8686 1.000
## 471 41 1 0.915 0.0412 0.8344 0.996
## 548 38 1 0.891 0.0466 0.8000 0.983
## 586 35 1 0.866 0.0518 0.7647 0.968
## 605 32 1 0.840 0.0568 0.7282 0.951
## 635 30 1 0.812 0.0615 0.6915 0.933
## 710 22 1 0.776 0.0690 0.6408 0.911
## 844 18 1 0.734 0.0776 0.5820 0.886
## 880 15 1 0.687 0.0867 0.5168 0.857
## 922 14 1 0.639 0.0936 0.4559 0.823
## 925 13 1 0.592 0.0988 0.3984 0.786
## 1030 8 1 0.522 0.1117 0.3036 0.741
## 1443 5 1 0.428 0.1323 0.1684 0.687
## 1449 4 1 0.333 0.1409 0.0569 0.609
## 1855 2 1 0.202 0.1665 0.0000 0.528
-log(NAfit$surv)
## [1] 0.00000000 0.02040816 0.02040816 0.02040816 0.04214729 0.06436952
## [7] 0.06436952 0.06436952 0.06436952 0.08875976 0.08875976 0.08875976
## [13] 0.11507555 0.11507555 0.11507555 0.14364698 0.14364698 0.14364698
## [19] 0.17489698 0.17489698 0.20823031 0.20823031 0.20823031 0.20823031
## [25] 0.20823031 0.20823031 0.20823031 0.20823031 0.25368486 0.25368486
## [31] 0.25368486 0.25368486 0.30924041 0.30924041 0.30924041 0.37590708
## [37] 0.44733565 0.52425873 0.52425873 0.52425873 0.52425873 0.52425873
## [43] 0.64925873 0.64925873 0.64925873 0.84925873 1.09925873 1.09925873
## [49] 1.59925873 1.59925873
plot(-log(NAfit$surv))
We can try an exponential distribution.
parafitexp=survreg(Surv(Time,delta)~1,data=dataset,dist='exp')
parafitexp
## Call:
## survreg(formula = Surv(Time, delta) ~ 1, data = dataset, dist = "exp")
##
## Coefficients:
## (Intercept)
## 7.733581
##
## Scale fixed at 1
##
## Loglik(model)= -148.5 Loglik(intercept only)= -148.5
## n= 50
The estimation of the intercept coefficient gives an estimation of \(\lambda\): \[ \hat{\lambda}=\exp(-intercept) \]
lambda=exp(-summary(parafitexp)$table[,1])
lambda
## [1] 0.0004378735